package com.jkl.controller.param;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jkl.entity.BaseResponseDTO;
import com.jkl.entity.param.ParamKey;
import com.jkl.service.param.inter.IParamKeyService;
import com.sun.xml.internal.rngom.parse.host.Base;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author liuzhennan
 * @create 2021-01-25 9:41
 */
@RestController
@Slf4j
@RequestMapping("/jky/paramKey")
public class ParamKeyController {
    @Autowired
    private IParamKeyService paramKeyService;

    /**
     * @author xgs
     * @return
     * @description 通过key_code查找不同系统中需要用到的值
     * @time 2021/4/23 9:30
     */
    @GetMapping("/getParamKeyByKeyCode")
    public BaseResponseDTO getParamKeyByKeyCode(@RequestParam(value = "keyCode") String keyCode) {
        BaseResponseDTO returnData = new BaseResponseDTO();
        if(org.apache.commons.lang3.StringUtils.isEmpty(keyCode)) {
            returnData.setResultCode("10001");
            returnData.setResultMessage("参数有误，请检查参数是正确");
            return returnData;
        }

        List<ParamKey> paramKeyList = paramKeyService.getParamKeyByKeyCode(keyCode);
        if( null == paramKeyList || paramKeyList.size() == 0 ) {
            returnData.setResultCode("10001");
            returnData.setResultMessage("参数有误，请检查参数是正确");
            return returnData;
        }else {
            JSONObject returnJson = new JSONObject();
            returnJson.put("paramKeyList",paramKeyList);
            returnData.setReturnData(returnJson);
            return returnData;
        }

    }

    @GetMapping("/getSystemParamKeySystemType")
    public BaseResponseDTO getSystemParamKeySystemType(){
        BaseResponseDTO returnData = new BaseResponseDTO();
        ParamKey paramKey = paramKeyService.selectBySystemType();
        JSONObject returnJson = (JSONObject) JSON.toJSON(paramKey);
        returnData.setReturnData(returnJson);
        return returnData;
    }

    @GetMapping("/getSystemParamKeySystemName")
    public BaseResponseDTO getSystemParamKeySystemName(){
        BaseResponseDTO returnData = new BaseResponseDTO();
        ParamKey paramKey = paramKeyService.selectBySystemName();
        JSONObject returnJson = (JSONObject) JSON.toJSON(paramKey);
        returnData.setReturnData(returnJson);
        return returnData;
    }

    @GetMapping("/getSystemParamKeySystemImg")
    public BaseResponseDTO getSystemParamKeySystemImg(@RequestParam(value = "keyName") String keyName){
        BaseResponseDTO returnData = new BaseResponseDTO();
        ParamKey paramKey = paramKeyService.selectBySystemImg(keyName);
        JSONObject returnJson = (JSONObject) JSON.toJSON(paramKey);
        returnData.setReturnData(returnJson);
        return returnData;
    }

    @GetMapping("/getSystemParamKeyDeptRoot")
    public BaseResponseDTO getSystemParamKeyDeptRoot(){
        BaseResponseDTO returnData = new BaseResponseDTO();
        ParamKey paramKey = paramKeyService.selectByDeptRoot();
        JSONObject returnJson = (JSONObject) JSON.toJSON(paramKey);
        returnData.setReturnData(returnJson);
        return returnData;
    }

    @GetMapping("/getSystemParamKeyMap")
    public BaseResponseDTO getSystemParamKeyMap(){
        BaseResponseDTO returnData = new BaseResponseDTO();
        ParamKey paramKey = paramKeyService.selectMap();
        JSONObject returnJson = (JSONObject) JSON.toJSON(paramKey);
        returnData.setReturnData(returnJson);
        return returnData;
    }
}
